package com.ggh.jinjilive.ui.social.record;

import androidx.databinding.ObservableField;
import androidx.lifecycle.MutableLiveData;

import com.ggh.jinjilive.mobile.ResultEntity;
import com.ggh.jinjilive.mobile.social.visitors.VisitorsRecord;
import com.ggh.jinjilive.remotedata.InterceptObserver;
import com.ggh.jinjilive.remotedata.systemapi.SystemApiService;
import com.ggh.jinjilive.ui.BaseViewModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class ExamineViewModel extends BaseViewModel {
    //访客记录
    public MutableLiveData<List<VisitorsRecord>> mVisitorsRecord = new MutableLiveData<>();
    //type=2
    public ObservableField<Integer> type = new ObservableField<>(0);

    public ExamineViewModel(SystemApiService apiCallInterface) {

        super(apiCallInterface);
    }

    /**
     * //1:查看我的，2：我查看的
     */
    public void accessList(){
        if (isRefresh) {
            page = 1;
        }else {
            page = page + 1;
        }
        Map<String, Object> paramsa = new HashMap<>();
        paramsa.put("page",page);
        paramsa.put("limit",pageSize);
        paramsa.put("type",type.get());
        addSubscribe(apiCallInterface.accessList(paramsa).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribeWith(new InterceptObserver<ResultEntity<List<VisitorsRecord>>>() {
                    @Override
                    public void onNextData(ResultEntity resultEntity) {
                        List<VisitorsRecord> visitorsRecordList = (List<VisitorsRecord>) resultEntity.getData();
                        mVisitorsRecord.setValue(visitorsRecordList);
                    }

                    @Override
                    public void onErrorNet(Throwable t, String netMsg) {

                    }
                }));
    }

}
